import { Component, OnInit } from '@angular/core';
import {HttpClient, HttpParams} from "@angular/common/http";
import {fa_IR} from "ng-zorro-antd/i18n";

@Component({
  selector: 'app-applog',
  templateUrl: './applog.component.html',
  styleUrls: ['./applog.component.css']
})
export class ApplogComponent implements OnInit {

  public keyword: string = "";
  public isShowTable: boolean = false;
  public data: any;
  public loading:boolean = false;
  public cost: number = 0;

  constructor(
    private http: HttpClient,
  ) { }

  ngOnInit(): void {
  }

  /**
   * 用于日志云的模糊查询
   */
  suspectQuery() {
    this.loading = true;
    this.isShowTable = false;
    let start = Date.now();
    // 异步的方式去发送请求
    const params = new HttpParams()
      .set('keyword', this.keyword);
    this.http.get<Response>("http://localhost:8080/es/log/suspect/query", {params}).subscribe(res => {
      // 如果获取数据成功，那么给与显示
      if (res) {
        this.data = res;
        this.isShowTable = true;
        this.loading = false;
      }
      let end = Date.now();
      this.cost = end - start;
      console.log(res);
    });
  }
}
